//
//  PingJiaViewController.m
//  XiangMu
//
//  Created by 康世标 on 15/8/13.
//  Copyright (c) 2015年 康世标. All rights reserved.
//

#import "PingJiaViewController.h"

@interface PingJiaViewController ()

@end

@implementation PingJiaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self.textView.layer setBorderWidth:.5];
    self.faBiaoBtn.backgroundColor = CL_00cc85;
    
    self.fuWuArrs  = [NSMutableArray arrayWithObjects:self.btn0,self.btn1,self.btn2,self.btn3,self.btn4, nil];
    
    self.zongTiArrs = [NSMutableArray arrayWithObjects:self.btn10,self.btn11,self.btn12,self.btn13,self.btn14, nil];
    
    
    
    [self mbporg]
    ;
    [self QingQiu];
}
- (void)mbporg{
    
    hud =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
}

- (void)QingQiu{
    
    [QingQiuShuJu getwoDeDingDanXiangQing:URL_DINGDANXIANGXIWEIPINGJIA number:self.orderId Block:^(NSDictionary *dic, BOOL isOK) {
        
        if (isOK) {
            
            if ([[dic valueForKey:@"status"] intValue]==200) {
                
                self.datasDic = [dic valueForKey:@"data"];
                
             
                [self XianShiShuJu]
                ;
                [hud hide:YES];
                
            }
            else{
                
                hud.mode = MBProgressHUDModeText;
                hud.labelText = [dic valueForKey:@"msg"];
                [hud hide:YES afterDelay:2];
                
            }
        }
        else{
            hud.mode = MBProgressHUDModeText;
            hud.labelText = @"网络连接超时";
            [hud hide:YES afterDelay:2];
            
        }
        
    }];
}
- (void)XianShiShuJu{
    
    self.leiXing.text = [NSString stringWithFormat:@"类型:%@",[self.datasDic valueForKey:@"carerType"]];
  
    NSString * startTime = [self upDated:[self.datasDic valueForKey:@"startTime"]==[NSNull null]?0:[[self.datasDic valueForKey:@"startTime"] longValue]];
    NSString * endTimer = [self upDated:[self.datasDic valueForKey:@"endTime"]==[NSNull null]?0:[[self.datasDic valueForKey:@"endTime"] longValue]];
    self.shiJian.text = [NSString stringWithFormat:@"时间:🕒 %@-%@",startTime,endTimer];
    
    self.danjian.text =[NSString stringWithFormat:@"%@",[self.datasDic valueForKey:@"price"]==[NSNull null]?@"":[self.datasDic valueForKey:@"price"]];
    self.danJiaType.text = [NSString stringWithFormat:@"/%@",[self.datasDic valueForKey:@"timeType"]];
    

}
-(NSString *)upDated:(long )str{
    
    
    if (str==0) {
        
        return @"";
    }
    
    
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:str/1000];
    
    NSDateFormatter * dataFormatter = [[NSDateFormatter alloc]init];
    
    [dataFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString * string= [dataFormatter stringFromDate:date];
    
    return string;
    
}


- (IBAction)faBiao:(UIButton *)sender{
    
    
    hud =[MBProgressHUD showHUDAddedTo:self.view animated:YES];

    if ([self.textView.text isEqualToString:@""]||self.textView==nil) {
        
        hud.mode = MBProgressHUDModeText;
        
        hud.labelText = @"请输入内容";
        
        [hud show:YES];
        [hud hide:YES afterDelay:2];
        return;
    }
    
    NSMutableDictionary * dic =[[NSMutableDictionary alloc]initWithCapacity:0];
    [dic setObject:[self.datasDic valueForKey:@"carerId"] forKey:@"carerId"];
    [dic setObject:[self.datasDic valueForKey:@"id"] forKey:@"orderId"];
    [dic setObject:self.textView.text forKey:@"appraise"];
    [dic setObject:@(self.index) forKey:@"sLength"]; //服务打分
    [dic setObject:@(self.indexs) forKey:@"tLength"]; //总体打分
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"ID"] forKey:@"userId"];
    
    [QingQiuShuJu dingDanPingJia:dic blcok:^(NSDictionary *dic, BOOL isOK) {
        
        if (isOK) {
            
            
            if ([[dic valueForKey:@"status"]intValue ]==200) {
              
                hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];
                
                
                hud.mode = MBProgressHUDModeCustomView;
                
                hud.labelText = @"发布成功";
                
                [hud show:YES];
                [hud hide:YES afterDelay:2];
                
                [self.navigationController popViewControllerAnimated:YES];
                

            }
            else{
                hud.mode = MBProgressHUDModeText;
                
                hud.labelText = [dic valueForKey:@"msg"];
                
                [hud show:YES];
                [hud hide:YES afterDelay:2];
            }
            
        }
        else{
         
            hud.mode = MBProgressHUDModeText;
            
            hud.labelText = @"网络加载失败";
            
            [hud show:YES];
            [hud hide:YES afterDelay:2];
        }
    }];
}

- (IBAction)FuWuBtn:(UIButton *)sender{

    for (UIButton * button in self.fuWuArrs)
    {
        
        [button setBackgroundImage:[UIImage imageNamed:@"wusewujiaoxing"] forState:UIControlStateNormal];
        

    }
    
    for (int i = 0; i<= sender.tag; i ++)
    {
            
            UIButton * button = [self.fuWuArrs objectAtIndex:i];
            
            [button setBackgroundImage:[UIImage imageNamed:@"wujiaoxing"] forState:UIControlStateNormal];
    }

    
    NSLog(@"-----%ld",(long)sender.tag);
    
    self.index = sender.tag+1;
    
}
- (IBAction)ZongTi:(UIButton *)sender{
    
    for (UIButton * button in self.zongTiArrs)
    {
        
        [button setBackgroundImage:[UIImage imageNamed:@"wusewujiaoxing"] forState:UIControlStateNormal];
        
        
    }
    
    for (int i = 0; i<= sender.tag; i ++)
    {
        
        UIButton * button = [self.zongTiArrs objectAtIndex:i];
        
        [button setBackgroundImage:[UIImage imageNamed:@"wujiaoxing"] forState:UIControlStateNormal];
    }
    
    
    NSLog(@"-----%ld",(long)sender.tag);
     self.indexs = sender.tag+1;

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
